package com.yanxu.lock.reentrantlock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/3/16-2025
 * @Description: 这里用一句话描述这个类的作用
 */
public class RecursionDemo {
    static ReentrantLock lock = new ReentrantLock();

    public static void accessResource() {
        lock.lock();
        try {
            System.out.println("对资源进行了处理!!!");
            //if (lock.getHoldCount() < 5) {
            while (lock.getHoldCount() < 5) {
                accessResource();
            }
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        accessResource();
    }
}